home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / jed096_1.zip / SLANG / SRC / SLANG.H < prev    next >
C/C++ Source or Header  |  1994-04-26  |  14KB  |  375 lines

  1. #ifndef DAVIS_SLANG_H_
  2. #define DAVIS_SLANG_H_
  3. /* 
  4.  * Copyright (c) 1992, 1994 John E. Davis 
  5.  * All rights reserved.
  6.  *
  7.  * Permission is hereby granted, without written agreement and without
  8.  * license or royalty fees, to use, copy, and distribute this
  9.  * software and its documentation for any purpose, provided that the
  10.  * above copyright notice and the following two paragraphs appear in
  11.  * all copies of this software.
  12.  *
  13.  * IN NO EVENT SHALL JOHN E. DAVIS BE LIABLE TO ANY PARTY FOR DIRECT,
  14.  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
  15.  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOHN E. DAVIS
  16.  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17.  *
  18.  * JOHN E. DAVIS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
  19.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  20.  * PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
  21.  * BASIS, AND JOHN E. DAVIS HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
  22.  * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  23.  */
  24.  
  25.  
  26. #ifdef USE_DOUBLE
  27. #define FLOAT double
  28. #else
  29. #define FLOAT float
  30. #endif
  31.  
  32.  
  33. #define LANG_MAX_NAME_LEN 30
  34. /* maximum length of an identifier */
  35. /* first char in identifiers is the hash */
  36.  
  37.  
  38. typedef struct SLang_Name_Type
  39.   {
  40. #ifdef SLANG_STATS
  41.      int n;                   /* number of times referenced */
  42. #endif
  43.      char name[LANG_MAX_NAME_LEN + 2]; /* [0] is hash */
  44.      unsigned short type;
  45.      long addr;
  46.   }
  47. SLang_Name_Type;
  48.  
  49.  
  50. typedef struct SLang_Load_Type
  51. {
  52.    int type;                   /* 'F' = file, 'S' = String, etc.. */
  53.    long name;                   /* file name, string address, ... */
  54.    long handle;                   /* FILE *, string address, etc... */
  55.    char *buf;                   /* buffer for file, etc... */
  56.    char *(*read)(struct SLang_Load_Type *);   /* function to call to read obj */
  57.    int n;                   /* line number, etc... */
  58.    char token[256];               /* token to be parsed */
  59.    char *ptr;                   /* input pointer */
  60. } SLang_Load_Type;
  61.  
  62.   extern volatile int SLang_Error;
  63.   /* Non zero if error occurs.  Must be reset to zero to continue. */
  64.  
  65.   extern int SLang_Traceback;
  66.   /* If non-zero, dump an S-Lang traceback upon error.  Available as 
  67.      _traceback in S-Lang. */
  68.  
  69.   extern char *SLang_User_Prompt;
  70.   /* Prompt to use when reading from stdin */
  71.   extern char SLang_Version[];
  72.  
  73.   extern int (*SLang_Error_Routine)(char *);
  74.   /* Pointer to application dependent error messaging routine.  By default,
  75.      messages are displayed on stderr. */
  76.  
  77.   extern void (*SLang_Dump_Routine)(char *);
  78.   /* Called if S-Lang traceback is enabled as well as other debugging 
  79.      routines (e.g., trace).  By default, these messages go to stderr. */
  80.   
  81.   extern void (*SLang_Interrupt)(void);
  82.   /* function to call whenever inner interpreter is entered.  This is 
  83.      a good place to set SLang_Error to USER_BREAK. */
  84.  
  85.   extern void (*user_clear_error)(void);
  86.   /* function that gets called when '_clear_error' is called. */
  87.   extern int (*user_open_slang_object)(SLang_Load_Type *); 
  88.   extern int (*user_close_slang_object)(SLang_Load_Type *);
  89.   /* user defined loading routines. */
  90.  
  91.  
  92.   /* If non null, these call C functions before and after a slang function. */
  93.   extern void (*SLang_Enter_Function)(char *);
  94.   extern void (*SLang_Exit_Function)(char *);
  95.  
  96.  
  97. /* Functions: */
  98.  
  99.    extern int init_SLang(void);   
  100.    /* This function is mandatory and must be called by all applications */
  101.    extern int init_SLfiles(void);
  102.    /* called if fputs, fgets, etc are need in S-Lang */
  103.    extern int init_SLmath(void);
  104.    /* called if math functions sin, cos, etc... are needed. */
  105.  
  106.    extern int init_SLunix(void);
  107.    /* unix system functions chmod, stat, etc... */
  108.  
  109.    extern int init_SLmatrix(void);
  110.    
  111.    int SLang_add_table(SLang_Name_Type *, char *);
  112.    /* add application dependent function table p1 to S-Lang.  A name p2 less 
  113.       than 32 characters must also be supplied.      
  114.       Returns 0 upon failure or 1 upon success. */
  115.  
  116.    extern int SLang_load_object(SLang_Load_Type *);
  117.    extern int SLang_load_file(char *);
  118.    /* Load a file of S-Lang code for interpreting.  If the parameter is
  119.    NULL, input comes from stdin. */
  120.  
  121.    extern void SLang_restart(int);
  122.    /* should be called if an error occurs.  If the passed integer is
  123.     * non-zero, items are popped off the stack; otherwise, the stack is 
  124.     * left intact.  Any time the stack is believed to be trashed, this routine
  125.     * should be called with a non-zero argument (e.g., if setjmp/longjmp is
  126.     * called). */ 
  127.  
  128.    extern void SLang_byte_compile_file(char *, int *);
  129.    /* takes a file of S-Lang code and ``byte-compiles'' it for faster
  130.     * loading.  The new filename is equivalent to the old except that a `c' is
  131.     * appended to the name.  (e.g., init.sl --> init.slc).  If the second 
  132.     * parameter is non-zero, preprocess the file only.
  133.     */
  134.  
  135.    extern void SLang_autoload(char *, char *);
  136.    /* Automatically load S-Lang function p1 from file p2.  This function
  137.       is also available via S-Lang */
  138.    
  139.    extern char *SLang_load_string(char *);
  140.    /* Like SLang_load_file except input is from a null terminated string. */
  141.    
  142.    extern void SLang_do_pop(void);
  143.    /* pops item off stack and frees any memory associated with it */
  144.    
  145.    extern int SLang_pop_integer(int *);
  146.    /* pops integer *p0 from the stack.  Returns 0 upon success and non-zero
  147.     * if the stack is empty or a type mismatch occurs, setting SLang_Error.
  148.     */
  149.  
  150.    extern int SLang_pop_string(char **, int *);
  151.    /* pops string *p0 from stack.  If *p1 is non-zero, the string must be
  152.     * freed after its use.  DO NOT FREE p0 if *p1 IS ZERO! Returns 0 upon
  153.     * success */
  154.       
  155.    extern int SLang_pop_float(FLOAT *, int *, int *);
  156.    /* Pops float *p1 from stack.  If *p3 is non-zero, *p1 was derived
  157.       from the integer *p2. Returns zero upon success. */
  158.       
  159.    extern long *SLang_pop_pointer(unsigned short *, int *);
  160.    /* Returns a pointer to object of type *p1 on top of stack. 
  161.       If *p2 is non-zero, the Object must be freed after use. */
  162.  
  163.    
  164.    extern void SLang_push_string(char *);
  165.    /* Push string p1 onto stack */
  166.    
  167.    extern void SLang_push_integer(int);
  168.    /* push integer p1 on stack */
  169.  
  170.    extern void SLang_push_malloced_string(char *);
  171.    /* The normal SLang_push_string mallocs space for the string.  This one
  172.       does not.  DO NOT FREE IT IF YOU USE THIS ROUTINE */
  173.  
  174.    extern int SLdefine_for_ifdef (char *);
  175.    /* Adds a string to the SLang #ifdef preparsing defines. SLang already
  176.       defines MSDOS, UNIX, and VMS on the appropriate system. */
  177.       
  178.    extern int SLang_is_defined(char *);
  179.    /* Return non-zero is p1 is defined otherwise returns 0. */
  180.    
  181.    extern int SLang_run_hooks(char *, char *, char *);
  182.    /* calls S-Lang function p1 pushing strings p2 and p3 onto the stack
  183.     * first.  If either string is NULL, it is not pushed. If p1 is not
  184.     * defined, 0 is returned. */
  185.  
  186.    extern int SLang_execute_function(char *);
  187.    /* Call S-Lang function p1 */
  188.  
  189.    extern char *SLang_find_name(char *);
  190.    /* Return a pointer to p1 in table if it is defined.  Returns NULL
  191.     * otherwise.  This is useful when one wants to avoid redundant strings. 
  192.     */
  193.  
  194.    extern char *SLang_rpn_interpret(char *);
  195.    /* Interpret string as reverse polish notation */
  196.  
  197.    extern void SLang_doerror(char *);
  198.    /* set SLang_Error and display p1 as error message */
  199.    
  200.    extern int SLang_add_array(char *, long *, int, int, int, int, 
  201.                   unsigned char, unsigned char);
  202.    /* This function has not been tested thoroughly yet.  Its purpose is to 
  203.     * allow a S-Lang procedure to access a C array. For example, suppose that 
  204.     * you have an array of 100 ints defined as:
  205.     *  
  206.     *  int c_array[100];
  207.     *
  208.     * By calling something like:
  209.     *
  210.     *   SLang_add_array ("array_name", (long *) c_array, 1, 100, 0, 0,
  211.              'i', LANG_IVARIABLE);
  212.     *
  213.     * the array can be accessed by the name 'array_name'.  This function 
  214.